<template>
  <div class="dynamic_table_wrapper" :class="{ dynamic_layer_table: props.config.type === 'layer' }">
    <div class="dynamic_table_icons" v-if="(props.icons && props.icons.length) || props.config.mode || props.config.graphical">
      <div class="dynamic_icons_left">
        <span v-for="(item, index) in icons" :key="index">
          <ImpExcel @success="(excelData) => loadDataSuccess(excelData, item)" v-if="item.key === 'localUpload'" v-permission="item.state.key" :timeZone="8" :dateFormat="''">
            <a-button :type="item.type || 'primary'" v-permission="item.state.key" :class="item.class">
              <i class="iconfont" :class="item.class"></i>
              {{ item.value }}
            </a-button>
          </ImpExcel>
          <template v-else-if="item.key === 'select'">
            <a-dropdown>
              <template #overlay>
                <a-menu>
                  <a-menu-item key="1" v-for="optin in item.options" @click="iconSubmit(optin)">
                    {{ optin.label }}
                  </a-menu-item>
                </a-menu>
              </template>
              <a-button :type="item.type || 'primary'">
                {{ item.value }}
                <i class="iconfont icon-chevron-down"></i>
              </a-button>
            </a-dropdown>
          </template>
          <a-button v-else :disabled="item.disabled" :type="item.type || 'primary'" v-if="!item.hidden" v-permission="item.state.key" :class="item.class" @click="iconSubmit(item)">
            <!-- <plus-outlined /> -->
            <i class="iconfont" :class="item.class"></i>
            {{ item.value }}
          </a-button>
          <a-tooltip v-if="item.state?.tipText">
            <template #title>{{ item.state.tipText }}</template>
            <i class="iconfont" :class="item.state.tipClass" :style="{ marginRight: '10px' }"></i>
          </a-tooltip>
        </span>
      </div>
      <div class="dynamicGraphical" v-if="props.config.graphical">
        <h2>{{ props.config.graphicalTitle }}</h2>
      </div>

      <div class="dynamic_icons_right" v-if="props.config.mode">
        <i class="iconfont icon-bulletpoint" :class="{ icon_activate: !isMode }" @click="isMode = false"></i>
        <i class="iconfont icon-app" :class="{ icon_activate: isMode }" @click="isMode = true"></i>
      </div>
    </div>
    <slot name="title" :isMode="isMode" :data="dataList.value" :selectedRows="selectedRows"></slot>
    <div class="dynamic_table" @mouseleave="() => (isShowSetting = false)">
      <div class="dynamic_screen_right" v-if="props.config.isScreen" >
        <div class="dynamic_screen_wrap" :class="isShowSetting ? '' : 'dynamic_screen_right_inactive'">
          <div class="dynamic_screen_list">
            <a-checkbox-group v-model:value="screenValue" @change="setColumns">
              <div class="dynamic_screen_item" v-for="item in screenList">
                <a-checkbox :value="item.key">{{ item.value }}</a-checkbox>
              </div>
            </a-checkbox-group>
          </div>
        </div>
        <i class="iconfont icon-setting" @mouseenter.self="() => (isShowSetting = true)" :class="isShowSetting ? 'dynamic_screen_right_active' : ''"></i>
        <!-- <a-button type="primary" @click="screenShow()">筛选</a-button> -->
      </div>
      <a-table
        :columns="columns"
        v-if="!isMode"
        :bordered="props.config.bordered"
        :scroll="Object.assign({ y: 500 }, props.config.scroll || {})"
        :pagination="false"
        :rowKey="props.config.rowKey || 'id'"
        :showHeader="props.config.isShowHeader === false ? false : true"
        :data-source="dataList.value"
        :row-selection="rowSelection"
        :showSorterTooltip="false"
        :expandIcon="customExpandIcon"
        @expand="expand"
        @expandedRowsChange="expandedRowsChange"
        :customRow="props.config.rowClick || (props.config.rowSelection && props.config.rowSelection.type === 'radio') ? rowClick : null"
        :row-class-name="getRowClassName"
      >
        <!-- 二层展开 -->
        <template v-if="props.config.childrenColumns" #expandedRowRender="{ record }">
          <a-table
            :columns="props.config.childrenColumns"
            :rowKey="props.config.childrenRowKey || 'id'"
            :data-source="record[props.config.childrenKey ? props.config.childrenKey : 'childrens']"
            :pagination="false"
            :row-selection="childrenRowSelection"
            @expand="threeExpand"
          >
            <!-- 三层展开 -->
            <template v-if="props.config.grandsonChildrenColumns" #expandedRowRender="{ record: threeRecord }">
              <a-table :columns="props.config.grandsonChildrenColumns" :data-source="threeRecord[props.config.childrenKey ? props.config.childrenKey : 'childrens']" :pagination="false">
                <template #bodyCell="{ column, index, text, record: childRecord }">
                  <!-- 序号 -->
                  <template v-if="column.type === 'index'">
                    <span>{{ index + 1 }}</span>
                  </template>
                  <!-- 图片 -->
                  <template v-if="column.type === 'img'">
                    <img :src="fileUrl(text)" @click="showViewImg(fileUrl(text))" alt="" class="table_img" />
                  </template>
                  <!-- 本地插槽 -->
                  <template v-if="column.type === 'slot'">
                    <slot :name="column.slotName" :column="column" :text="text" :record="childRecord"></slot>
                  </template>
                  <!-- 含有父信息的本地插槽 -->
                  <template v-if="column.type === 'fatherslot'">
                    <slot :name="column.slotName" :column="column" :text="text" :index="index" :record="record"></slot>
                  </template>
                  <!-- 数据字典过滤器 -->
                  <template v-else-if="column.type === 'dictionary'">
                    <!-- tag标签 -->
                    <template v-if="column.tag && typeof column.tag === 'object'">
                      <a-tag :color="column.tag[text]">{{ dictionaryFn(column.state, text) }}</a-tag>
                    </template>
                    <template v-else-if="column.colors && typeof column.colors === 'object'">
                      <span :style="{ color: column.colors[text] }">{{ dictionaryFn(column.state, text) }}</span>
                    </template>
                    <template v-else>
                      {{ dictionaryFn(column.state, text) }}
                    </template>
                  </template>
                  <!-- 按钮 -->
                  <template v-else-if="column.type === 'actions'">
                    <template v-for="(part, index) in column.handle">
                      <span
                        class="dynamic_table_btn"
                        :class="part.class"
                        :index="index"
                        v-permission="part.state.key"
                        v-if="isHidden(childRecord, part)"
                        :key="index"
                        @click="tableControl(childRecord, part)"
                      >
                        <template v-if="part.state.loading">
                          <a-button disabled type="primary" size="mini" :loading="true"> {{ part.text }}</a-button>
                        </template>
                        <template v-else-if="part.state.button">
                          <a-button type="primary" size="mini"> {{ part.text }}</a-button>
                        </template>
                        <template v-else>
                          {{ part.text }}
                        </template>
                      </span>
                    </template>
                  </template>
                </template>
              </a-table>
            </template>
            <template #bodyCell="{ column, index, text, record: childRecord }">
              <!-- 序号 -->
              <template v-if="column.type === 'index'">
                <span>{{ index + 1 }}</span>
              </template>
              <!-- 图片 -->
              <template v-if="column.type === 'img'">
                <img :src="fileUrl(text)" @click="showViewImg(fileUrl(text))" alt="" class="table_img" />
              </template>
              <!-- 本地插槽 -->
              <template v-if="column.type === 'slot'">
                <slot :name="column.slotName" :column="column" :text="text" :record="childRecord"></slot>
              </template>
              <!-- 含有父信息的本地插槽 -->
              <template v-if="column.type === 'fatherslot'">
                <slot :name="column.slotName" :column="column" :text="text" :record="record"></slot>
              </template>
              <!-- 数据字典过滤器 -->
              <template v-else-if="column.type === 'dictionary'">
                <!-- tag标签 -->
                <template v-if="column.tag && typeof column.tag === 'object'">
                  <a-tag :color="column.tag[text]">{{ dictionaryFn(column.state, text) }}</a-tag>
                </template>
                <template v-else-if="column.colors && typeof column.colors === 'object'">
                  <span :style="{ color: column.colors[text] }">{{ dictionaryFn(column.state, text) }}</span>
                </template>
                <template v-else>
                  {{ dictionaryFn(column.state, text) }}
                </template>
              </template>
              <!-- 按钮 -->
              <template v-else-if="column.type === 'actions'">
                <template v-for="(part, index) in column.handle">
                  <span
                    class="dynamic_table_btn"
                    :class="part.class"
                    :index="index"
                    v-permission="part.state.key"
                    v-if="isHidden(childRecord, part)"
                    :key="index"
                    @click="tableControl(childRecord, part)"
                  >
                    <template v-if="part.state.loading">
                      <a-button disabled type="primary" size="mini" :loading="true"> {{ part.text }}</a-button>
                    </template>
                    <template v-else-if="part.state.button">
                      <a-button type="primary" size="mini"> {{ part.text }}</a-button>
                    </template>
                    <template v-else-if="part.state.select">
                      <a-dropdown>
                        <template #overlay>
                          <a-menu>
                            <a-menu-item v-for="(optin, index) in part.state.options" :key="index" @click="tableControl(record, optin)">
                              {{ optin.label }}
                            </a-menu-item>
                          </a-menu>
                        </template>
                        <span>{{ part.text }}</span>
                      </a-dropdown>
                    </template>
                    <template v-else>
                      {{ part.text }}
                    </template>
                  </span>
                </template>
              </template>
            </template>
          </a-table>
        </template>

        <!-- 自定义表头插槽 -->
        <template #headerCell="{ title, column, text, record }">
          <template v-if="column.required">
            <span><i class="custom_icon_required">*</i>{{ column.title }}</span>
          </template>
          <template v-if="column.type === 'slot'">
            <template v-if="column.state.slotTitleName">
              <div :class="{ fill_padding: column.state.fillPadding }">
                <slot :name="column.state.slotTitleName" :title="title" :column="column" :text="text" :record="record"></slot>
              </div>
            </template>
            <template v-else>
              {{ title }}
            </template>
          </template>
        </template>

        <template #bodyCell="{ column, index, text, record }">
          <!-- 序号 -->
          <template v-if="column.type === 'index'">
            <span>{{ index + 1 }}</span>
          </template>
          <!-- 下拉 -->
          <template v-else-if="column.controlType === 'select'">
            <span :class="{ err_line: ruleHint[index] && ruleHint[index].includes(column.key) }">
              <InputSelect :dataForm="record" v-model:formData.sync="record[column.key]" :question="column" :index="index"></InputSelect>
            </span>
          </template>
          <!-- 输入框 -->
          <template v-else-if="column.controlType === 'input'">
            <span :class="{ err_line: ruleHint[index] && ruleHint[index].includes(column.key) }">
              <InputItem :dataForm="record" v-model:formData.sync="record[column.key]" :question="column" :index="index"></InputItem>
            </span>
          </template>
          <!-- 时间格式 -->
          <template v-else-if="column.controlType === 'time'">
            <span :class="{ err_line: ruleHint[index] && ruleHint[index].includes(column.key) }">
              <InputTime :dataForm="record" v-model:formData.sync="record[column.key]" :question="column" :index="index"></InputTime>
            </span>
          </template>
          <!-- 上传图片 -->
          <template v-else-if="column.controlType === 'img'">
            <span :class="{ err_line: ruleHint[index] && ruleHint[index].includes(column.key) }">
              <InputUpload :dataForm="record" v-model:formData.sync="record[column.key]" :question="column" :index="index"></InputUpload>
            </span>
          </template>
          <!-- 图片 -->
          <template v-else-if="column.type === 'img'">
            <div class="fill_padding">
              <div v-if="Array.isArray(text)" class="dynamic_imgs">
                  <template v-for="(src) in text ">
                    <img :src="fileUrl(src)" @click="showViewImg(fileUrl(src))" alt="" class="table_img" :style="{ width: column.state.width, height: column.state.height }" />
                  </template>
              </div>
              <template v-else>
                <img :src="fileUrl(text)" @click="showViewImg(fileUrl(text))" alt="" class="table_img" :style="{ width: column.state.width, height: column.state.height }" />
              </template>
            </div>
          </template>
          <!-- 弹层编辑 -->
          <template v-else-if="column.type === 'edit'">
            <span :title="text" class="cursor text-primary" @click="layerEdit(column, record)">{{ text }}</span>
          </template>
          <!-- 跳转路由 -->
          <template v-else-if="column.type === 'router' || column.type === 'url'">
            <span :title="text" class="cursor text-primary" @click="tableControl(record, column.state)">{{ text }}</span>
            <!-- <span class="cursor text-primary" @click="proxy.$goTo(column.state.url,column.state.params||{})">{{ text }}</span> -->
          </template>
          <!-- 数据字典过滤器 -->
          <template v-else-if="column.type === 'dictionary'">
            <!-- tag标签 -->
            <template v-if="column.tag && typeof column.tag === 'object'">
              <a-tag :color="column.tag[text]">{{ dictionaryFn(column.state, text) }}</a-tag>
            </template>
            <template v-else-if="column.colors && typeof column.colors === 'object'">
              <span :title="text" :style="{ color: column.colors[text] }">{{ dictionaryFn(column.state, text) }}</span>
            </template>
            <template v-else>
              <span :title="dictionaryFn(column.state, text)">{{ dictionaryFn(column.state, text) }}</span>
            </template>
          </template>
          <!-- 数组展示字段 -->
          <template v-else-if="column.type === 'array'">
            <span :title="aItem[column.state.keyName] || ''" class="dynamic_table_array" v-for="(aItem, aIndex) in text"><i v-if="aIndex">, </i>{{ aItem[column.state.keyName] || '' }}</span>
          </template>
          <!-- 过滤器 -->
          <template v-else-if="column.type === 'time'">
            <span :title="text == null ? '-' : timeFilter(text, column.state.fmt || 'YYYY-MM-DD HH:mm:ss')">{{
              text == null ? '-' : timeFilter(text, column.state.fmt || 'YYYY-MM-DD HH:mm:ss')
            }}</span>
          </template>
          <!-- 本地自定义slot -->
          <template v-else-if="column.type === 'custom'" :slot="column.scopedSlots.customRender" slot-scope="record"> </template>
          <!-- 本地插槽 -->
          <template v-else-if="column.type === 'slot'">
            <div :class="{ fill_padding: column.state.fillPadding }">
              <slot :name="column.state.slotName" :column="column" :text="text" :record="record" :index="index"></slot>
            </div>
          </template>
          <!-- 按钮 -->
          <template v-else-if="column.dataIndex === 'actions'">
            <template v-for="(part, index) in column.handle">
              <span
                class="dynamic_table_btn"
                :class="part.class"
                :index="index"
                v-permission="part.state.key"
                v-if="isHidden(record, part)"
                :key="index"
                @click="tableControl(record, part)"
                :title="part.text"
              >
                <template v-if="part.state.loading">
                  <a-button disabled type="primary" size="mini" :loading="true"> {{ part.text }}</a-button>
                </template>
                <template v-else-if="part.state.button">
                  <a-button type="primary" size="mini"> {{ part.text }}</a-button>
                </template>
                <template v-else-if="part.state.select">
                  <a-dropdown>
                    <template #overlay>
                      <a-menu>
                        <template v-for="(optin, index) in part.state.options">
                          <a-menu-item v-if="isHidden(record, optin)" :key="index" @click="tableControl(record, optin)">
                            {{ optin.label || optin.text }}
                          </a-menu-item>
                        </template>
                      </a-menu>
                    </template>
                    <span>{{ part.text }}</span>
                  </a-dropdown>
                </template>
                <template v-else>
                  {{ part.text }}
                </template>
              </span>
            </template>
          </template>
          <!-- 默认显示 -->
          <template v-else>
            <span :class="column.class" :style="column.style">
              <i v-if="column.icon" class="iconfont" :class="column.icon"></i>
              {{ text }}
            </span>
          </template>
        </template>
      </a-table>
      <div v-else class="dynamic_list">
        <slot name="tableHaled" :data="props.tables"></slot>
        <div class="dynamic_list_line" v-for="(item, index) in dataList.value" :style="props.config.modeConfig.style">
          <slot name="tableList" :index="index" :data="item"></slot>
        </div>
      </div>
      <!-- //按钮插槽 -->
      <slot name="tableBtns" :data="dataList.value"></slot>
      <div class="dynamic_pagination" v-if="!props.config.noPagination && dataList.value && dataList.value.length">
        <a-pagination
          v-model:current="pagination.pageNumber"
          v-model:page-size="pagination.pageSize"
          :pageSizeOptions="pagination.pageSizeOptions"
          show-quick-jumper
          show-size-changer
          :showLessItems="true"
          :total="pagination.totalCount"
          :show-total="(total) => `共 ${total} 条`"
          @change="onPagination"
        />
      </div>
    </div>
    <div class="dynamic_layer_buttons">
      <a-button @click="layerClear">{{ props.config.cancelText || '取消' }}</a-button>
      <a-button v-if="!props.config.cancelSubmit" type="primary" @click="save">确定</a-button>
    </div>
    <!-- 查看图片放大 -->
    <transition name="el-fade-in-linear">
      <div class="img_preview" v-show="previewState" @click="previewState = false">
        <img :src="previewUrl" alt="" />
      </div>
    </transition>
  </div>
</template>

<script setup lang="ts">
import { getCurrentInstance, nextTick, reactive, onMounted, createVNode, ref, onUnmounted, unref, computed, h } from 'vue';
import { TableBase, TextTable } from '../table-base';
import { ImpExcel, ExcelData } from '../../Excel';
import { message, Modal } from 'ant-design-vue';
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import { isHidden } from '@/utils';
import { dictionaryFn, timeFilter } from '@/filters/index';
import {
  DYNAMICLAYERCLEAR,
  DYNAMICLAYERFORM,
  DYNAMICLAYERTABLE,
  DYNAMICLAYERTABLEDATA,
  DYNAMICLAYERUPLOAD,
  DYNAMICLOCALICONS,
  DYNAMICLOCALTABLE,
  DYNAMICLTABLECLICKROW,
  DYNAMICLTABLEDELETE,
  RESETTABLE,
  SEARCHSERVE,
  UPLOADESERVE
} from '@/mixins/subject/subject-types';
import { Subscription } from 'rxjs';
import { filter } from 'rxjs/operators';
import XEUtils from 'xe-utils';
import { assignParams, downloadFile, paramsData } from '../../publicMethod';
import { downloadFile as downloadFileApiRequest, fileUrl } from '@/config/api/common/api';
import InputSelect from '../table-question/input-select/input-select.component.vue';
import InputItem from '../table-question/input-item/input-item.component.vue';
import InputTime from '../table-question/input-time/input-time.component.vue';
import InputUpload from '../table-question/input-upload/input-upload.component.vue';

let $subscribeSub: Subscription;

let props = defineProps<{ tables: TableBase<any>[]; config: any; icons?: any }>();
const { proxy }: any = getCurrentInstance();
const emit = defineEmits(['update:formData', 'expand', 'threeExpand', 'expandedRowsChange', 'onPagination', 'onSelectChange']);
//搜索参数
let searchParams: any = reactive({});
//选择数据
const selectedRows = ref<any[]>([]);
let selectedRowKeys: any = reactive([]);

//分页参数
let pagination: any = reactive({
  totalCount: 0,
  pageNumber: 1,
  pageSize: 50,
  pageSizeOptions: ['25', '50', '100']
});
//数据存放
let dataList: any = reactive([]);
//图片预览放大
let previewState: any = ref(false);
let previewUrl: any = ref('');

//table配置参数
let rowSelection: any = reactive(null);
let columns: any = reactive([]);

//table分页
let tablePagination: any = {
  pageSizeOptions: ['25', '50', '100'],
  pageSize: pagination.pageSize,
  showQuickJumper: true,
  showSizeChanger: true
};

const onPagination = (pageNumber, pageSize) => {
  pagination.pageNumber = pageNumber;
  pagination.pageSize = pageSize;
  console.log('分页事件', pagination);
  getData(Object.assign({}, props.config.params, searchParams.value));
};

//开启模式
const isMode = ref(props.config.graphical?props.config.graphical:false);

// 子表格配置参数
let childrenRowSelection: any = reactive(null);
let childrenSelectedRowKeys: any = ref([]);
const childSelectedRows = ref<any[]>([]);

onMounted(() => {
  if (props.config.rowSelection) {
    //type:多选/单选=> checkbox/radio,集体参数可见https://antdv.com/components/table-cn#rowSelection
    rowSelection = computed(() => {
      return Object.assign(
        {
          onChange: onSelectChange,
          selectedRowKeys: selectedRowKeys.value,
          onSelect: onParentSelectChange,
          onSelectAll
        },
        props.config.rowSelection
      );
    });

    if (props.config.childrenRowSelection) {
      childrenRowSelection = computed(() => {
        return Object.assign(
          {
            onSelect: onChildrenSelectChange,
            selectedRowKeys: childrenSelectedRowKeys.value,
            onSelectAll: onChildSelectAll
          },
          props.config.rowSelection
        );
      })
    }
  }
  init();
  subWatch();
  if (!props.config.autoSearch) {
    getData();
  }
});

// 监听嵌套子表格行选择事件
const onChildrenSelectChange = (record: any, selected: any, selectedRows: any) => {
  const tempIndex = childrenSelectedRowKeys.value.findIndex(item => item === record[props.config.childrenRowKey || 'id']);
  // 存选中id集合和具体内容集合
  if (tempIndex === -1) {
    // 勾选
    childrenSelectedRowKeys.value = [...childrenSelectedRowKeys.value, record[props.config.childrenRowKey || 'id']];
    childSelectedRows.value = [...childSelectedRows.value, record];
  } else {
    // 取消勾选
    childrenSelectedRowKeys.value.splice(tempIndex, 1);
    childSelectedRows.value.splice(tempIndex, 1);
  }
  emit('onSelectChange', childrenSelectedRowKeys);
};

// 监听父表格全选/反选事件
const onSelectAll = (selected: any, selectedRows: any, changeRows: any) => {
  if (!props.config.childrenColumns) return;
  // 只针对包含二级子节点的数据进行处理
  const tempIds = [];
  const tempRows = [];
  changeRows.forEach(item => {
    if (item[props.config.childrenKey || 'childrens']?.length) {
      item[props.config.childrenKey || 'childrens'].forEach(aitem => {
        tempIds.push(aitem[props.config.childrenRowKey || 'id']);
        tempRows.push(aitem);
      })
    }
  })
  // 数据初始化，将当前全选下所有数据清空（反选）
  childrenSelectedRowKeys.value = childrenSelectedRowKeys.value.filter(item => !tempIds.includes(item));
  childSelectedRows.value = childSelectedRows.value.filter(item => !tempIds.includes(item[props.config.childrenRowKey || 'id']))
  if (selected) {
    // 全选
    childSelectedRows.value = [...childSelectedRows.value, ...tempRows];
    childrenSelectedRowKeys.value = [...childrenSelectedRowKeys.value, ...tempIds]
    return 
  }
}
// 监听二级表格全选/反选事件
const onChildSelectAll = (selected: any, selectedRows: any, changeRows: any) => {
  const tempIds = changeRows.map(item => item[props.config.childrenRowKey || 'id']);
  // 数据初始化，将当前全选下所有数据清空（反选）
  childrenSelectedRowKeys.value = childrenSelectedRowKeys.value.filter(item => !tempIds.includes(item));
  childSelectedRows.value = childSelectedRows.value.filter(item => !tempIds.includes(item[props.config.childrenRowKey || 'id']))
  if (selected) {
    // 全选
    childSelectedRows.value = [...childSelectedRows.value, ...changeRows];
    childrenSelectedRowKeys.value = [...childrenSelectedRowKeys.value, ...tempIds]
    return;
  }
}

// 监听行选择事件
const onParentSelectChange = (record: any, selected: any, selectedRows: any) => {
  // TODO 暂时还没有和内部的onSelectChange方法进行整合，所以只针对允许选中嵌套子表格行内容进行性逻辑处理
  // TODO 暂时只视作子节点数据存放在childrens字段中
  if (!props.config.childrenRowSelection) return;
  // 不存在嵌套子节点数据，则不进行逻辑处理
  if (!record.childrens) return;
  const tempChildrenIds = record.childrens.map(item => item[props.config.rowKey || 'id']);
  // 初始化，先将子节点统一过滤，再针对是否勾选父节点判断是否添加子节点
  childrenSelectedRowKeys.value = childrenSelectedRowKeys.value.filter(item => !tempChildrenIds.includes(item));
  childSelectedRows.value = childSelectedRows.value.filter(item => !tempChildrenIds.includes(item[props.config.rowKey || 'id']))
  if (!selectedRowKeys.value?.includes(record[props.config.rowKey || 'id'])) {
    // 勾选 - 全选子节点数据
    childrenSelectedRowKeys.value = [...childrenSelectedRowKeys.value, ...tempChildrenIds];
    childSelectedRows.value = [...childSelectedRows.value, ...record.childrens];
  }
}


//解绑
onUnmounted(() => {
  if ($subscribeSub != undefined) {
    $subscribeSub.unsubscribe();
  }
  proxy.$NotificationFormSub.clearParams();
  // store.dispatch(`info/${types.REMOVEINFO}`);
});

//初始化
const init = () => {
  if (!props.config.pagination) {
    tablePagination = true;
  } else {
    tablePagination = Object.assign(tablePagination, props.config.pagination);
  }
  columns = getColumns();
  screenList.value = getColumns();
  screenValue.value = screenList.value.map((res) => res.key);
};

//筛选
const screenList = ref([]);
const screenValue = ref([]);
const setColumns = (arr = null) => {
  if (arr) {
    screenValue.value = arr;
  } else {
    screenValue.value = getColumns().map((res) => res.key);
  }
  columns = getColumns().filter((res) => screenValue.value.includes(res.key));
  if (props.config.rowSelection) {
    //type:多选/单选=> checkbox/radio,集体参数可见https://antdv.com/components/table-cn#rowSelection
    rowSelection = computed(() => {
      return Object.assign(
        {
          onChange: onSelectChange,
          selectedRowKeys: selectedRowKeys.value,
          onSelectAll
        },
        props.config.rowSelection
      );
    });
  } else {
    rowSelection = null;
  }
};
const getColumns = () => {
  let arr = [];
  props.tables.forEach((item: any) => {
    if (!item.hidden) {
      arr.push(
        Object.assign(
          {
            title: item.value,
            dataIndex: item.key
          },
          item,
          Object.assign({ ellipsis: true }, item.columns || {})
        )
      );
    }
  });
  return arr;
};

//监听动态表单
const subWatch = () => {
  $subscribeSub = proxy.$NotificationFormSub
    .getParams()
    .pipe(filter((res: any) => res !== 0))
    .subscribe((item: any) => {
      try {
        console.log('table刷新',item,props.config);
        if (item.key === SEARCHSERVE) {
          if (item.state.name && props.config.name && item.state.name !== props.config.name) {
            return;
          }
          //表单的搜索条件
          searchParams.value = item.value;
          if (searchParams.value) {
            for (const key in searchParams.value) {
              if (!searchParams.value.hasOwnProperty(key) && searchParams.value[key] !== 0 && searchParams.value[key] !== false) {
                delete searchParams.value[key];
              } else if (
                Array.isArray(searchParams.value[key]) &&
                (searchParams.value[key].length === 0 || (searchParams.value[key].length === 1 && !searchParams.value[key][0] && searchParams.value[key][0] !== 0))
              ) {
                delete searchParams.value[key];
              }
            }
          }

          // init();
          pagination.pageNumber = 1;
          console.log('getData事件1');
          getData(Object.assign({}, props.config.params, searchParams.value));
        }
        if (item.value.name || item.name) {
          if ((item.key === RESETTABLE || item.key === UPLOADESERVE ) && (item.value.name === props.config.name || item.name === props.config.name)) {
            getData();
          }
        } else {
          if (item.key === RESETTABLE) {
            getData();
          }
        }
      } catch (error) {}
    });
};

//查看图片
const showViewImg = (url) => {
  console.log('dynamic-table.component.vue', 'showViewImg');
  previewState.value = true;
  previewUrl.value = url;
};

//展开事件
const expand = (expanded, record) => {
  console.log('店家展开', record);
  emit('expand', record);
};
//三层展开事件
const threeExpand = (expanded, record) => {
  console.log('店家展开', record);
  emit('threeExpand', record);
};
const expandedRowsChange = (expandedRows) => {
  emit('expandedRowsChange', expandedRows);
};

//选择方法
const pagingLocalData: any = reactive({});
const selectedValue: any = reactive([]);
const onSelectChange = (oldSelectedRowKeys: any, oldSelectedRows: any) => {
  selectedRowKeys.value = oldSelectedRowKeys;
  selectedValue.value = oldSelectedRowKeys;
  selectedRows.value = oldSelectedRows;
  if (props.config.isPagingLocalData) {
    //开启本地分页数据
    pagingLocalData[pagination.pageNumber] = oldSelectedRows;
    let arr: any = [];
    if (pagingLocalData) {
      for (const key in pagingLocalData) {
        if (pagingLocalData[key] && pagingLocalData[key].length) {
          arr.push(...pagingLocalData[key]);
        }
      }
    }
    selectedRows.value = arr; //选中的数据
    emit('onSelectChange', pagingLocalData);
    return;
  }
  emit('onSelectChange', oldSelectedRows);
};
//默认选中
const autoSelection = (oldSelectedRowKeys: any) => {
  console.log('自动赋值', oldSelectedRowKeys);
  selectedRowKeys.value = oldSelectedRowKeys;
  rowSelection.selectedRowKeys = selectedRowKeys.value;
  //开启本地分页数据-回显
  if (props.config.isPagingLocalData && pagingLocalData[pagination.pageNumber] && pagingLocalData[pagination.pageNumber].length) {
    selectedRowKeys.value = pagingLocalData[pagination.pageNumber].map((res) => res[props.config.rowKey || 'id']);
  }
};

//删除方法
const pubDelete = (part: any, arr: any, isTable: boolean = false) => {
  let keysArr = null;
  if (part.state.deleteShowKey) {
    keysArr = arr.map((res) => res[part.state.deleteShowKey]);
  }
  Modal.confirm({
    title: part.state.title ? part.state.title : '是否确认删除所选内容？',
    icon: createVNode(ExclamationCircleOutlined),
    autoFocusButton: null,
    okText: '确定',
    centered: true,
    cancelText: '取消',
    content: `${part.state.content || ''} ${keysArr ? keysArr.join(',') : ''} ${part.state.deleteAfterHint || ''}`,
    onOk() {
      let params: any = {};
      // if (isTable) {
      //   params = assignParams(arr[0], part, searchParams.value);
      // } else {
      let name: string = 'id';
      if (part.params && part.params.length && part.params[0].id) {
        name = part.params[0].id;
      }
      let deleteId = arr.map((item: any) => (part.state.parent ? item[part.state.parent][name] : item[name])); //默认删除第一个

      if (part.state.type === 'array') {
        if (part.state.keyName) {
          params[part.state.keyName] = deleteId;
        } else {
          params = deleteId;
        }
      } else {
        params[part.state.keyName || name] = deleteId[0];
      }
      if (part.state.assign) {
        params = Object.assign(params, part.state.assign);
      }
      // }
      console.log('看下删除参数', params, part);
      if (part.state.islocal) {
        proxy.$NotificationPubSub.pushParams({ key: DYNAMICLTABLEDELETE, value: { data: params, part } });
        return;
      }
      proxy.$Http
        .api(
          part.url || part.state.url,
          part.urlName ? {} : params,
          part.postType || part.state.postType ? part.postType || part.state.postType : 'delete',
          part.urlParema ? true : false,
          part.urlName ? params[part.urlName] : ''
        )
        .then((data: any) => {
          if (data.success || part.state.skipError) {
            !part.state.skipError && message.success('删除成功');
            const length = Array.isArray(params) ? params.length : Object.values(params).length;
            const totalPage = Math.ceil((pagination.totalCount - length) / pagination.pageSize); // 总页数
            pagination.pageNumber = pagination.pageNumber > totalPage ? totalPage : pagination.pageNumber;
            pagination.pageNumber = pagination.pageNumber < 1 ? 1 : pagination.pageNumber;
            if (part.state.delay) {
              //延迟
              setTimeout(() => {
                getData(Object.assign({}, props.config.params, searchParams.value));
              }, part.state.delay);
              return;
            }
            getData(Object.assign({}, props.config.params, searchParams.value));
            proxy.$NotificationPubSub.pushParams({ key: DYNAMICLTABLEDELETE, value: { data: params, part } });
          }
        });
    },
    onCancel() {},
    class: 'test'
  });
};

//icon按钮
const iconSubmit = (item: any) => {
  switch (item.key) {
    case 'add':
      // 弹窗添加后的的selectedRows.value
      if (selectedRows.value.length > 0) {
        proxy.$goTo(item.state.url, item.state.params ? Object.assign({ id: selectedRows.value.map((res) => res.id) }, item.state.params) : { id: selectedRows.value.map((res) => res.id) });
      } else {
        message.warning('请先选中一个选项');
      }
      break;
    case 'router':
      proxy.$goTo(item.state.url, item.state.params);
      break;
    case 'hint':
      if (selectedRows.value.length > 0) {
        pubHint(selectedRows.value, item, true);
      } else {
        message.warning('请先选中一个选项');
      }
      break;
    case 'delete':
      if (selectedRows.value.length > 0) {
        pubDelete(item, unref(selectedRows));
      } else {
        message.warning('请先选中一个选项');
      }
      break;
    case 'download': //导出
      if (item.state.type == 'all') {
        // 导出全部
        if (!dataList.value || !dataList.value.length) {
          message.warning('没有数据');
          return;
        }
        pubDownload(item);
      } else {
        // 导出选中
        if (selectedRows.value.length > 0) {
          Modal.confirm({
            title: item.state?.confirmTitle ? item.state?.confirmTitle : '导出提示框',
            icon: createVNode(ExclamationCircleOutlined),
            autoFocusButton: null,
            okText: '确定',
            centered: true,
            cancelText: '取消',
            content: item.state?.confirmContent ? item.state?.confirmContent : '是否确定导出你所选择的数据？',
            onOk: () => {
              pubDownload(item, unref(selectedRows));
            },
            onCancel: () => {}
          });
        } else {
          message.warning('请先选中一个选项');
        }
      }
      break;
    case 'upload': //导入
      proxy.$NotificationPubSub.pushParams({ key: DYNAMICLAYERUPLOAD, value: item });
      break;
    case 'local': //本地
    proxy.$NotificationPubSub.pushParams({ key: DYNAMICLOCALICONS, value: item, state: { selected: unref(selectedRows), childSelected: unref(childSelectedRows) } });
      if (item.state.url) {
        proxy.$goTo(item.state.url, item.state.params);
      }
      break;
    case 'layerTable': //弹层table
      proxy.$NotificationPubSub.pushParams({
        key: DYNAMICLAYERTABLE,
        value: {
          tables: item.state.table || item.state.tables,
          form: item.state.form,
          config: item.state.config,
          index: item.state.index || 0,
          name: item.state.name || item.state.config.name
        }
      });
      break;
    case 'layerFrom': //弹层from
      if (item.state.config.params) {
        item.state.config.params = Object.assign({}, item.state.config.assign || {});
      }
      if (item.state.config?.isSelect) {
        //开启选择
        if (selectedRows.value.length == 0) {
          return message.warning('请先选中一个选项');
        } else {
          item.state.config.params[item.state.config.keyName || 'ids'] = selectedRows.value.map((res) => res[props.config.rowKey || 'id']);
        }
      }
      proxy.$NotificationPubSub.pushParams({
        key: DYNAMICLAYERFORM,
        value: {
          config: item.state.config,
          form: item.state.form,
          name: item.state.name || item.state.config.name
        }
      });
      break;
  }
};
//table按钮
const tableControl = (data: any, part: any) => {
  switch (part.type) {
    case 'url':
      proxy.$goTo(part.url, assignParams(data, part, searchParams.value));
      break;
    case 'router':
      proxy.$goTo(part.url, part.params);
      break;
    case 'delete':
      pubDelete(part, [data], true);
      break;
    case 'hint':
      pubHint(data, part);
      break;
    case 'download': //导出、下载
      if (part.fileId) {
        downloadFileApiRequest(data[part.fileId]).then((res) => {
          downloadFile(res, data[part.fileName || '下载文件']);
        });
      }
      break;
    case 'layer':
      if (data.id) {
        part.state.config.id = data.id;
      }
      if (part.params) {
        let params = assignParams(data, part);
        part.state.config.params = params;
      }
      proxy.$NotificationPubSub.pushParams({ key: DYNAMICLAYERFORM, value: { data, part } });
      break;
    case 'layerTable': //弹层table
      if (part.params) {
        let params = assignParams(data, part);
        part.state.config.params = params;
      }
      proxy.$NotificationPubSub.pushParams({
        key: DYNAMICLAYERTABLE,
        value: {
          tables: part.state.table || part.state.tables,
          form: part.state.form,
          config: part.state.config,
          index: part.state.index || 0,
          name: part.state.name || part.state.config.name
        }
      });
      break;
    case 'layerFrom': //弹层from
      if (part.params) {
        let params = assignParams(data, part);
        part.state.config.params = params;
      }
      if (part.state.config.dataParams) {
        part.state.config.data = assignParams(data, { params: part.state.config.dataParams });
      }
      if (part.state.config.urlName) {
        part.state.config.id = data[part.state.config.urlName];
      }
      proxy.$NotificationPubSub.pushParams({
        key: DYNAMICLAYERFORM,
        value: {
          config: part.state.config,
          form: part.state.form,
          name: part.state.name || part.state.config.name
        }
      });
      break;
    case 'local':
      //把数据传给本地处理
      proxy.$NotificationPubSub.pushParams({ key: DYNAMICLOCALTABLE, value: { data, part } });
      break;
    default:
  }
};

//导出
const pubDownload = (data: any, list?: any) => {
  const idName = 'ids';
  let params: any = {};
  if (list) {
    //扩展额外自选参数
    if (data.state.extendCode) {
      //extendCode:[{ key:value }]
      params[data.state.idName || idName] = list.map((res) => {
        return paramsData(res, { params: data.state.extendCode });
      });
    } else {
      // 导出默认选中
      params[data.state.idName || idName] = list.map((res) => res[data.state.keyName || 'id']);
    }
  } else {
    // 导出全部
    params = Object.assign(
      {},
      {
        ...searchParams.value,
        pageSize: pagination.pageSize,
        pageNumber: pagination.pageNumber
      }
    );
  }
  if (data.state.params) {
    params = Object.assign(params, data.state.params);
  }
  if (data.state.beforeWithMethod) {
    params = data.state.beforeWithMethod(params);
  }
  if (data.state.url) {
    let fileName: any = data.state.fileName;
    proxy.$Http
      .api(
        data.state.url,
        params,
        data.state.postType || 'post',
        data.state.urlParema,
        data.state.urlName ? params[data.state.urlName] : '',
        Object.assign({ responseType: 'blob' }, data.state.httpOpt)
      )
      .then((res: any) => {
        if (res) {
          if(res instanceof Blob) return downloadFile(res, fileName ? fileName : '下载文件.xlsx');
          if ((res?.headers['content-disposition'] || res.data)&&data.state.autoName) {
            downloadFile(res.data, res.headers['content-disposition'] ? decodeURI(res.headers['content-disposition'].split("attachment;filename*=utf-8''")[1]) : '下载文件.xlsx');
          } 
          return;
        } else {
          message.error('导出数据失败');
        }
      });
  }
};

// dataList  statu: 1初盘，2复盘，3平盘 5转派回显
const updateDataList = (arr: any = [], statu: Number) => {
  dataList.value.forEach((item) => {
    arr.forEach((value) => {
      if (item.deviceId == value.deviceId) {
        if (statu == 1) {
          item.initialResult = value.inventoryResult;
          item.initialTakePicture = value.takePicture;
        } else if (statu == 2) {
          item.replayResult = value.inventoryResult;
          item.replayTakePicture = value.takePicture;
        } else if (statu == 3) {
          item.plateWay = value.plateWay;
          item.plateRemark = value.plateRemark;
        } else if (statu == 4) {
          if (value.value1.length < 0) {
            item.value1 = value.value1;
            item.value2 = value.value2;
            item.initialExecutors = value.initialExecutors;
            item.replayExecutors = value.value2;
          } else if (value.value2.length < 0) {
            item.value1 = value.value1;
            item.value2 = value.value2;
            item.initialExecutors = value.value1;
            item.replayExecutors = value.replayExecutors;
          }
        } else if (statu == 5) {
          item.value = value.executeIds;
        }
      }
    });
  });
  console.log('方法调用', dataList.value);
};

//扩展接口自定义字段
const extendCodes = (dynamicFields = null) => {
  if (dynamicFields) {
    let arr = [];
    screenList.value = getColumns();
    for (const key in dynamicFields) {
      let obj: any = {
        title: dynamicFields[key],
        dataIndex: key,
        ellipsis: true,
        width: dynamicFields[key].length * 30,
        align: screenList.value[0].align
      };
      arr.push(obj);
    }
    let name = screenList.value.find((res) => res.state.name);
    let index = screenList.value.map((res) => res.state.name || '').indexOf(props.config.dynamicName);
    if (name && index !== -1) {
      screenList.value.splice(index + 1, 0, ...arr);
    } else {
      screenList.value.splice(screenList.value.length - 1, 0, ...arr);
    }
    screenValue.value = screenList.value.map((res) => res.key);
    setColumns();
  }
};

//获取数据
const getData = (msg: any = null) => {
  ruleHint.value = {};
  if (props.config.queryUrl) {
    let params = Object.assign({}, props.config.params, msg ? msg : {});
    if (props.config.isPageIndex) {
      //分页偏移量
      params.pageIndex = props.config.data.length || 0;
    }
    params.pageNumber = pagination.pageNumber;
    params.pageSize = pagination.pageSize;
    proxy.$Http
      .api(
        props.config.queryUrl,
        params,
        props.config.protType ? props.config.protType : 'get',
        props.config.urlParema ? true : false,
        props.config.urlName === 'id' ? props.config.id : props.config.urlName || ''
      )
      .then((data: any) => {
        console.log('请求数据了', data);
        //自定义字段
        if (data && data.dynamicFields) {
          extendCodes(data.dynamicFields);
        }
        if (data && data.data) {
          pagination.totalCount = data.total ? +data.total : data.data.length;
          if (props.config.beforeWithMethod && typeof props.config.beforeWithMethod === 'function') {
            data.data = props.config.beforeWithMethod(data.data);
          }
          //可以传值
          if (props.config.data && props.config.data.length) {
            dataList.value = [...props.config.data, ...data.data];
            pagination.totalCount += props.config.data.length;
          } else {
            dataList.value = [...data.data];
          }
          autoPaging();
          nextTick(() => {
            emit('onPagination', pagination);
            if (props.config.defaultValue) {
              //默认选中
              autoSelection(props.config.defaultValue);
            }
          });
        } else {
          if (props.config.data && props.config.data.length) {
            dataList.value = [...props.config.data];
            pagination.totalCount = +dataList.value.length;
            //默认选中
            if (props.config.defaultValue) {
              autoSelection(props.config.defaultValue);
            }
          } else {
            dataList.value = [];
            pagination.totalCount = 0;
          }
          autoPaging();
        }
      });
  } else {
    if (props.config.data && props.config.data.length) {
      if (props.config.dynamicFields) {
        extendCodes(props.config.dynamicFields);
      }
      dataList.value = [...props.config.data];
      pagination.totalCount = +dataList.value.length;
      autoPaging();
      //默认选中
      if (props.config.defaultValue) {
        autoSelection(props.config.defaultValue);
      }
    } else {
      dataList.value = [];
      pagination.totalCount = 0;
    }
  }
};

//自动分页
const autoPaging = () => {
  if (dataList.value.length > pagination.pageSize) {
    let start = (pagination.pageNumber - 1) * pagination.pageSize;
    dataList.value = dataList.value.slice(start, start + pagination.pageSize);
  }
};

//取消弹层
const layerClear = () => {
  proxy.$NotificationPubSub.pushParams({ key: DYNAMICLAYERCLEAR, value: { name: 'table' } });
};

//弹层保存
const save = () => {
  if (proxy.config.name === 'proLayerTable') {
    if (unref(selectedRows).length < 1) {
      proxy.$NotificationPubSub.pushParams({
        key: DYNAMICLAYERTABLEDATA,
        value: { data: unref(selectedRows), index: proxy.config.index, name: proxy.config.name }
      });
    } else {
      layerClear();
      proxy.$NotificationPubSub.pushParams({
        key: DYNAMICLAYERTABLEDATA,
        value: { data: unref(selectedRows), index: proxy.config.index, name: proxy.config.name }
      });
    }
  } else {
    layerClear();
    proxy.$NotificationPubSub.pushParams({
      key: DYNAMICLAYERTABLEDATA,
      value: { data: unref(selectedRows), index: proxy.config.index, name: proxy.config.name }
    });
  }
};

//公用弹层提示
const pubHint = (data: any, part: any, isTable: boolean = false) => {
  if (part.state && part.state.hintData) {
    Modal.confirm({
      title: part.state.hintData.title,
      icon: createVNode(ExclamationCircleOutlined),
      autoFocusButton: null,
      okText: '确定',
      centered: true,
      cancelText: '取消',
      content: part.state.hintData.content ? part.state.hintData.content : '',
      onOk: () => {
        let params: any = {};
        if (isTable) {
          params = Object.assign({}, part.state.assign || {});
          params[part.state.keyName || 'ids'] = data.map((res) => res[part.state.keyValue || 'id']);
        } else {
          params = paramsData(data, part);
        }

        proxy.$Http
          .api(
            part.url || part.state.url,
            part.urlName || part.state.urlName ? {} : params,
            part.postType || part.state.postType || 'post',
            part.urlParema || part.state.urlParema ? true : false,
            part.urlName ? params[part.urlName] : part.state.urlName ? params[part.state.urlName] : ''
          )
          .then((data: any) => {
            if (data.success) {
              message.success('操作成功!');
            }
            getData();
            if (part.state.callBack) {
              proxy.$NotificationPubSub.pushParams({ key: 'DynamicTableControlHint', value: { data, part } });
            }
          });
      },
      onCancel: () => {}
    });
  }
};

//按钮弹层from
const layerEdit = (column, record) => {
  console.log(column, record);
  if (column.state.url) {
    proxy.$goTo(column.state.url, { id: record.id });
    return;
  }
  const config = XEUtils.clone(column.state.config || {}, true);
  const form = XEUtils.clone(column.state.form);
  let data = null;
  if (record[config.layerIdName] || record.id) {
    config.id = config.layerIdName ? record[config.layerIdName] : record.id;
  } else {
    data = record;
  }
  proxy.$NotificationPubSub.pushParams({
    key: DYNAMICLAYERFORM,
    value: {
      data,
      config,
      form
    }
  });
};

//本地上传解析文件
const loadDataSuccess = (excelDataList: ExcelData[], item) => {
  console.log('看下解析文件', excelDataList);
  const tableListRef = ref([]);
  tableListRef.value = [];
  for (const excelData of excelDataList) {
    const {
      header,
      results,
      meta: { sheetName }
    } = excelData;
    const columns = [];
    for (const title of header) {
      columns.push({ title, dataIndex: title });
    }
    tableListRef.value.push({ title: sheetName, dataSource: results, columns });

    //丢给本地处理
    if (item.value.state.isLocal) {
      proxy.$NotificationPubSub.pushParams({ key: DYNAMICLOCALTABLE, value: { data: tableListRef.value, part: item.value } });
      return;
    }
    if (item.value.state.url) {
      proxy.$Http.api(item.value.state.url, tableListRef.value[0].dataSource, item.value.state.postType ? item.value.state.postType : 'post').then((data: any) => {
        message.success('上传成功！');
      });
    }
  }
};

//校验,是否为空或者正则
const ruleHint = ref({});
const submitVerify = () => {
  ruleHint.value = {};
  let ruleRequired = props.tables.filter((res: any) => !res.hidden && res.required);
  let ruleReg = props.tables.filter((res: any) => !res.hidden && res.reg);
  let isAgeValid = true;
  let isRuleReg = true;
  console.log('检验看下', ruleRequired, ruleReg);
  if (ruleRequired && ruleRequired.length) {
    ruleRequired.forEach((item) => {
      dataList.value.forEach((res, index) => {
        if (res[item.key] === '' || res[item.key] === null || res[item.key] === undefined) {
          isAgeValid = false;
          if (ruleHint.value[index]) {
            ruleHint.value[index].push(item.key);
          } else {
            ruleHint.value[index] = [item.key];
          }
        }
      });
    });
  }
  if (ruleReg && ruleReg.length) {
    ruleReg.forEach((item) => {
      dataList.value.forEach((res, index) => {
        if (!item.reg.test(res[item.key] + '')) {
          isRuleReg = false;
          if (ruleHint.value[index]) {
            ruleHint.value[index].push(item.key);
          } else {
            ruleHint.value[index] = [item.key];
          }
        }
      });
    });
  }

  return isAgeValid && isRuleReg ? true : false;
};

//提交验证
const onFinish = (fn: any = null) => {
  let state = submitVerify();
  if (state) {
    if (fn) {
      fn(dataList.value);
    }
  }
};

// 选择行
const selectedRowIndex: any = ref(null);
// 选择行
const rowClick = (record, index) => {
  return {
    onClick: (event) => {
      selectedRowIndex.value = record[props.config.rowKey || 'id'];
      onSelectChange([record[props.config.rowKey || 'id']], [record]);
      proxy.$NotificationPubSub.pushParams({ key: DYNAMICLTABLECLICKROW, value: { data: record, name: proxy.config.name } });
    }
  };
};
// 每行样式
const getRowClassName = (record) => {
  //给条件符合的条加上class
  // rowClass:{
  //   showKey:[{ key:'status',value: 2 }],
  //   className:'selected-row-8c'
  // }
  if(props.config.rowClass &&  isHidden(record,{showKey: props.config.rowClass.showKey}) ){
    return  props.config.rowClass.className || 'selected-row' 
  }
  return selectedRowIndex.value === record[props.config.rowKey || 'id'] ? 'selected-row' : '';
};

//展开icon
const customExpandIcon = (prop: any) => {
  let { expanded, onExpand, record } = prop;
  if (props.config.childrenKey && record[props.config.childrenKey] && record[props.config.childrenKey].length > 0) {
    return h('div', {
      class: `cursor iconfont ${expanded ? 'icon-chevron-down' : 'icon-chevron-right'}`,
      attrs: {
        role: 'button'
      },
      onclick: (event: Event) => {
        onExpand(record, event);
      }
    });
  }
};
const isShowSetting = ref(false);
defineExpose({
  getData,
  selectedRows,
  dataList,
  onFinish,
  pagingLocalData,
  pagination,
  updateDataList,
  selectedValue,
  screenValue,
  setColumns,
  selectedRowKeys,
  selectedRowIndex,
  isMode
});
</script>

<style lang="less" scoped>
@import url('./dynamic-table.component.less');
</style>
